WeblogService Application
What Is the WeblogService Application?
It has always been a goal to allow computers to exchange information over the web in a seamless manner, in the same way that people do. Web services are a recent attempt to provide universal access to applications. A web service is simply an application that is made available using a standard set of protocols. As long as two applications can agree on a protocol, any two computers on the Internet can have a conversation.
One of the exciting features of ColdFusion MX is that any ColdFusion component can be turned into a web service by changing a simple attribute. Invoking a web service in ColdFusion is no different than dealing with any other type of object. ColdFusion is therefore an ideal language for working with this exciting technology.
Another exciting technology in use on the Internet is RSS (Really Simple Syndication). RSS is a simple XML format that allows you to syndicate information. Typically, weblogs and other content are summarized and the information in the summaries is made available using RSS. While these RSS feeds are useful for people to read, there is also value in computers interacting with them as well. It is with this spirit in mind that we created WeblogService.
WeblogService is a simple application that allows you to expose any RSS feed (regardless of version) as a web service. Once this feed has been exposed, clients can query your RSS data as though it were a database. For example, a client could ask for all RSS entries that were created by a particular author or that were created on a certain day. By exposing your RSS in this manner, both the server (the author of the RSS) and the client (the consumer of the RSS document) benefit. Authors get to make all their data available in a very simple manner. Clients get access to this data—and, more importantly, can query it in a sophisticated manner to find just the information they need.
Installing WeblogService
Before installing WeblogService, shut down your ColdFusion server. Copy rssu.jar and weblogservice.jar to wwwroot/WEB-INF/lib, where wwwroot appears under the CFusionMX installation folder.
Copy all the .cfm and WeblogService.cfc files into a folder under your webroot. Then copy the examples folder to a location under wwwroot.
Configure your application according to the instructions in the next section.
Finally, start your ColdFusion server, browse to the examples folder you installed under webroot, and experiment with the included samples.
Configuring WeblogService
WeblogService contains a file named Application.cfm. This file is unique in that it contains the configurable aspects of the application. You need to edit this file for your installation of WeblogService to be useful. The table below describes the different configuration options in this file.
| Variable Name | Definition |
|---|---|
| application.rssUrl | The URL to the RSS feed; can be local or remote |
| application.parsedFeedKeyName | The name of the variable to be used to save the query containing data from the feed in the application scope |
| application.refresh.passwordRequired | Boolean; determines whether or not a password has to be specified at a URL parameter in order for the refresh.cfm page to execute fully |
| application.refresh.password | The password that should be passed into refresh.cfm |
| application.refresh.passwordHashed | Boolean; determines whether or not the specified password is MD5 hashed in the Application.cfm file (for additional security) |
| application.ping.passwordRequired | Boolean; determines whether or not a password has to be specified as a URL parameter in order for ping.cfm to execute fully |
| application.ping.password | The password that should be passed into ping.cfm through a URL parameter |
| application.ping.passwordHashed | Boolean; determines whether or not the specified password is MD5 hashed in the Application.cfm file (for additional security) |
| application.weblogService.passwordRequired | Boolean; determines whether or not a password has to be passed into the queryPosts function |
| application.weblogService.password | The password that should be passed into the queryPosts function |
| application.weblogService.passwordHashed | Boolean; determines whether or not the specified password is MD5 hashed in the Application.cfm file (for additional security) |
Using WeblogService
Once you have configured WeblogService and have restarted your ColdFusion server, you are ready to use it. There are three ways to interact with WeblogService.
The first way is by accessing the page refresh.cfm. Accessing this page reparses the currently configured RSS URL. For performance reasons, WeblogService does not retrieve the RSS associated with it every time someone uses its service. Instead, it retrieves it only when the application initially starts and whenever refresh.cfm or ping.cfm is accessed. You can access refresh.cfm with a single parameter named "password." This should be the password specified in Application.cfm, if Application.cfm requires one.
The second way to access WeblogService is by using ping.cfm, which behaves exactly like refresh.cfm but returns a valid XML-RPC response. This method is preferred by such tools as Movable Type and Blogger. Ping.cfm also supports a password parameter.
The final, and most interesting, way to access WeblogService is by using WeblogService.cfc—specifically the queryPosts method. This method has been marked as having the access type "remote." By setting this attribute to remote, you effectively turn WeblogService.cfc into a web service.
The queryPosts method takes three arguments: query, queryPass, and maxrows. The argument queryPass is the optional password specified in Application.cfm; maxrows is the maximum number of rows that the query returned by this method will return. This easily allows you to limit the number of results you get back. Finally, query is an SQL string that describes what information you are looking for.
The table name you use in the SQL statement will always be prefixed by "application." and will be named by the configuration value application.parsedFeedKeyName. For example, if application.parsedFeedKeyName has the value "foo," then the table name that you can query will be application.foo.
These are the columns available in the SQL statement:
- author
- category
- comments
- description
- guid
- link
- pubDate
- title
- type
For example, consider the case where application.parsedFeedKeyName is set to RSS. The following would be a legal query:
SELECT category, pubDate, title FROM application.rss WHERE author = 'ben'
The returned value of the queryPosts method is of type query. In ColdFusion, for example, you can treat the result of the queryPosts method like any other query object. Whether the query object comes from queryPosts or your local database is irrelevant; they can be treated identically.
See the included examples for a sample of invoking this web service using ColdFusion.
WeblogService was a fun application to write. It exercises some of the best features that ColdFusion has to offer. All RSS parsing is handled by the RSSU package, which demonstrates ColdFusion's ability to integrate with Java. The ability to create query objects and execute arbitrary SQL on them allows you to expose an extremely powerful mechanism for accessing RSS that couldn't be easier to write. Finally, you can turn the code into a web service by simply setting the access attribute to remote. Putting all these pieces together gives you an application that's easy to author, yet is extremely powerful.